package scan.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import scan.annotation.MyXA;
import scan.dao.FirstDao;
import scan.dao.SecondDao;
import scan.po.AdressPO;
import scan.util.IDWorker;

import javax.transaction.xa.XAException;
import java.net.UnknownHostException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

@RestController
public class TestController {
    @Autowired
    public FirstDao firstDao;
    @Autowired
    public SecondDao secondDao;
    @RequestMapping("insert")
    @MyXA
    public void insert() throws UnknownHostException, SQLException, XAException {
        Date date=new Date();
        Random r = new Random();
        AdressPO orderPO=new AdressPO();
        orderPO.setAddressId(IDWorker.getInstance("eshop_address").nextId());
        orderPO.setUserId(orderPO.getAddressId());
        orderPO.setCreateUserId(orderPO.getAddressId());
        orderPO.setModifyUserId(orderPO.getAddressId());
        orderPO.setProvinceCode(String.valueOf(r.nextInt(33)+1));
        orderPO.setCityCode(1L);
        orderPO.setRegionCode(String.valueOf(r.nextInt(89)+1));
        orderPO.setCreateTime(date);
        orderPO.setDetail("使用读写分离");
        orderPO.setAddressName("");
        orderPO.setModifyTime(date);
        orderPO.setCountryCode("");
        orderPO.setPhone("");
        firstDao.insert(orderPO);
        secondDao.insert(orderPO);
        System.out.println(1/0);
    }
}
